<?php
/**
 * Created by PhpStorm
 * User: whh
 * Date: 2022/12/15
 * Time: 14:20
 */

namespace app\common\coroutinePool;


use think\facade\Env;
use Swoole\Database\PDOConfig;
use Swoole\Database\PDOPool;

class MysqlPoolCoroutine
{
    private static $instance = null;

    public static function getInstance()
    {
        $host = Env::get('database.hostname', '');
        $database = Env::get('database.database', '');
        $username = Env::get('database.username', '');
        $password = Env::get('database.password', '');
        $pool = new PDOPool((new PDOConfig)
            ->withHost($host)
            ->withPort(3306)
            // ->withUnixSocket('/tmp/mysql.sock')
            ->withDbName($database)
            ->withCharset('utf8mb4')
            ->withUsername($username)
            ->withPassword($password)
        );
        return $pool;
    }
}